package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Document;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class DocumentDao {
	
	private DBHelp<Document> db = new DBHelp<Document>();
	
	public void Save (String id,String title,String desc,String createtime,String t_employee_id) {
		String sql = "insert into t_document(id,title,desc,createtime,t_employee_id) values(?,?,?,?,?)";
		db.executeSQL(sql, id,title,desc,createtime,t_employee_id);
	}
	
	public List<Document> FindAll () {
		String sql = "select id,title,desc,createtime,t_employee_id from t_document";
		return db.executeQueryForList(sql, new DocumentRowMapper());
	}
	
	private class DocumentRowMapper implements RowMapper<Document> {
		
		public Document mapperRow (ResultSet rs) throws SQLException {
			
			Document document = new Document();
			document.setId(rs.getString("id"));
			document.setTitle(rs.getString("title"));
			document.setDesc(rs.getString("desc"));
			document.setCreatetime(rs.getString("createtime"));
			document.setT_emlpoyee_id(rs.getString("t_emlpoyee_id"));
			return document;
		}
	}
}
